﻿//日期格式化输出
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
 (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
 RegExp.$1.length == 1 ? o[k] :
 ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

$.fn.numeral = function () {
    $(this).css("ime-mode", "disabled");
    this.bind("keypress", function () {
        if (event.keyCode == 46) {
            if (this.value.indexOf(".") != -1) {
                return false;
            }
        } else {
            return event.keyCode >= 46 && event.keyCode <= 57;
        }
    });
    this.bind("blur", function () {
        if (this.value.lastIndexOf(".") == (this.value.length - 1)) {
            this.value = this.value.substr(0, this.value.length - 1);
        } else if (isNaN(this.value)) {
            this.value = "";
        }
    });
    this.bind("paste", function () {
        var s = clipboardData.getData('text');
        if (!/\D/.test(s));
        value = s.replace(/^0*/, '');
        return false;
    });
    this.bind("dragenter", function () {
        return false;
    });
    this.bind("keyup", function () {
        if (/(^0+)/.test(this.value)) this.value = this.value.replace(/^0*/, '');
    });
};

$(document).ready(function () {
    //登录
    $('.username input').focus(function () {
        $('.username label').hide(); ;
    });

    $('.username input').blur(function () {
        if ($('.username input').val() == "") {
            $('.username label').show();
        }
    });

    $('.password input').focus(function () {
        $('.password label').hide(); ;
    });

    $('.password input').blur(function () {
        if ($('.password input').val() == "") {
            $('.password label').show();
        }
    });

    //注册
    $('.read input[type=checkbox]').click(function () {

        var registerbtn = $('.register_btns input[type=image]');
        if ($(this).is(":checked")) {

            registerbtn.removeAttr("disabled");
        }
    });

    $('.register_btns input[type=image]').click(function () {

        if (!$('.read input[type=checkbox]').is(":checked")) {
            alert("请先阅读会员权益和义务！");
            return false;
        }

    });

    //设置
    $('#settings,#settings ul').bind("mouseover", function () {

        $('#settings ul').removeClass("settingsvisible");
    });

    $('#settings,#settings ul').bind("mouseout", function () {

        $('#settings ul').addClass("settingsvisible");
    });
});